package com.multithreading.chart1.sleep;

/**
 * @author chenqb
 * @project_name: java-multithreading
 * @package_name: com.cqb.sleep
 * @ClassName: sleepTest2
 * @description: 演示当一个线程处于睡眠状态时。如果另外一个线程中断它将抛出异常的情况
 * Author by cqb, Date on 2020/6/29，7:23
 * PS: Not easy to write code, please indicate.
 */
public class SleepTest2 {
    public static void main(String[] args) throws InterruptedException{
        //创建线程a
        Thread thread=new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println("child threadA is in sleep");
                    Thread.sleep(10000);
                    System.out.println("child threadA is in awake");
                }catch (InterruptedException e){
                    e.printStackTrace();
                }
            }
        });
        //启动线程
        thread.start();
        //主线程休眠2s
        Thread.sleep(2000);
        //在主线程中断子线程
        thread.interrupt();
    }
}
